package cn.zl.springcloud.controller;

/**
 * @author zhanglang
 * @Date 2020/4/10
 */

import cn.zl.springcloud.pojo.Dept;
import cn.zl.springcloud.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 提供Restful服务
 * @author mec
 */
@RestController
public class DeptController {


    @Autowired
    private DeptService deptService;

    /**
     * 获取一些配置的信息，得到具体的微服务
     */
/*    @Autowired
    private DiscoveryClient client;*/


    @PostMapping("/dept/add")
    public boolean addDept(@RequestBody Dept dept) {
        System.out.println(dept);
        return deptService.addDept(dept);
    }

    @GetMapping("/dept/get/{id}")
    public Dept queryById(@PathVariable("id") long id) {
        return deptService.queryById(id);
    }

    @GetMapping("/dept/list")
    public List<Dept> queryAll() {
        return deptService.queryAll();
    }

    /**
     * 注册进来的微服务，获取一些消息
     * 获取微服务列表清单
     * @return
     */
/*    @GetMapping("/dept/discovery")
    public Object discovery(){
        List<String> services = client.getServices();
        System.out.println(services);
        // 得到一个具体的微服务信息，通过id
        List<ServiceInstance> instances = client.getInstances("SPRINGCLOUD-PROVIDER-DEPT");
        for (ServiceInstance instance : instances) {
            System.out.println(instance.getHost()+instance.getPort()+instance.getUri()+instance.getServiceId());
        }
        return this.client;
    }*/

}

